package com.yeren.servlet.tarena.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
	/*
	 * 获取连接对象
	 */
	public static Connection getConnection() throws Exception{
		Connection conn=null;
		try{
			Class.forName("oracle.jdbc.OracleDriver");
			conn = DriverManager
					.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",
							"scott", "tiger");
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return conn;
	}
	
	/*
	 * 关闭连接对象
	 */
	public static void close(Connection conn) throws Exception{
		if(conn!=null){
			try{
				conn.close();
			}catch(SQLException e){
				e.printStackTrace();
				throw e;
			}
			
		}
	}
	
	public static void main(String args[]) throws Exception{
		System.out.println(getConnection());
	}
}
